package net.gamebookengine.viewer;

import roboguice.activity.RoboActivity;
import roboguice.inject.InjectView;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class AboutActivity extends RoboActivity
{
	private final static Uri				MStockDe		= Uri.parse("http://www.mstock.de");
	private final static Uri				LippoDesignDe	= Uri.parse("http://www.lippo-design.de");
	
	@InjectView(R.id.version) TextView		version;
	@InjectView(R.id.MatthiasStock) View	matthiasStock;
	@InjectView(R.id.PatrickRehder) View	patrickRehder;
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_about);
		
		try
		{
			version.setText(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
		}
		catch (NameNotFoundException e)
		{
			version.setText("-");
		}
		
		matthiasStock.setOnClickListener(new OpenUriOnClickListener(MStockDe));
		patrickRehder.setOnClickListener(new OpenUriOnClickListener(LippoDesignDe));
	}
	
	private class OpenUriOnClickListener implements OnClickListener
	{
		private final Uri	uri;
		
		public OpenUriOnClickListener(Uri uri)
		{
			this.uri = uri;
		}
		
		public void onClick(View v)
		{
			Intent intent = new Intent(Intent.ACTION_VIEW);
			intent.setData(uri);
			startActivity(intent);
		}
	}
}
